//
//  HP_GoodsCollectionViewCell.m
//  JinFuThree
//
//  Created by 爱尚 on 2018/8/30.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "HP_GoodsCollectionViewCell.h"
#import "HomePageViewController.h"
#import "Mediator+Consume.h"

@implementation HP_GoodsCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = 6;
        
        [self initialize];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
        [self addGestureRecognizer:tap];
        
        
    }
    return self;
}

-(void)tapAction{
    UIViewController *detailVC = [[Mediator sharedInstance] Consume_goodsDetailViewController:@"id"];
    
    HomePageViewController *mainVC = (HomePageViewController *)self.nextResponder.nextResponder.nextResponder .nextResponder.nextResponder.nextResponder;
    [mainVC.navigationController pushViewController:detailVC animated:YES];
}
-(void)initialize{
    
    _goodImageView = [[UIImageView alloc]init];
    _goodImageView.image = [UIImage imageNamed:@"Bitmap"];
    [self addSubview:_goodImageView];
    [_goodImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(30);
        make.right.mas_equalTo(self.mas_right).offset(-30);
        make.top.mas_equalTo(self.mas_top).offset(12);
        make.height.mas_equalTo(self.goodImageView.mas_width);
    }];
    
    _goodNameLabel = [[UILabel alloc]init];
    _goodNameLabel.text = @"Apple iphoneX 国行正品";
    _goodNameLabel.textColor = HexColor(0x454545);
    _goodNameLabel.font = [UIFont systemFontOfSize:13];
    [self addSubview:_goodNameLabel];
    [_goodNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(9);
        make.right.mas_equalTo(self.mas_right).offset(-9);
        make.top.mas_equalTo(self.goodImageView.mas_bottom).offset(12);
        make.height.mas_offset(@13);
    }];
    
    _goodPriceLabel = [[UILabel alloc]init];
    _goodPriceLabel.text = @"￥5499";
    _goodPriceLabel.textColor =HexColor(0x999999);
    _goodPriceLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:_goodPriceLabel];
    [_goodPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.goodNameLabel);
        make.top.mas_equalTo(self.goodNameLabel.mas_bottom).offset(3);
        make.height.mas_offset(@12);
    }];
    
    _programLabel = [[PriceView alloc]init];
    [_programLabel updateInfoPrice:@"458.25" periods:@"12" priceShowType:PriceShowTypeRedPeriods];
    [self addSubview:_programLabel];
    [_programLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.goodPriceLabel);
        make.top.mas_equalTo(self.goodPriceLabel.mas_bottom).offset(10);
        make.height.mas_offset(@14);
    }];
}

+(CGSize)calculateSize:(id)data{
    return CGSizeMake(ScreenWidthMao/2.0-16, 200*ScreenWidthMao/375);
}
@end
